package com.example.tests;

import static com.example.fw.RandomizeHelper.generateRandomSuffix;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;

import org.testng.annotations.Test;

import com.example.fw.Folders;

public class TestFolderCreation extends TestBase
{

	@Test
	public void testFolderCreation()
	{
		String folder = generateRandomSuffix("newSingleFolder");
		Folders oldFolders = app.getFolderHelper().getFolders();
		assertThat(app.getFolderHelper().createFolder(folder), is(nullValue()));
		Folders newFolders = app.getFolderHelper().getFolders();
		assertThat(newFolders, equalTo(oldFolders.withAdded(folder)));
	}

	@Test(enabled = true)
	public void testVariousFolderCreation()
	{
		String folder1 = generateRandomSuffix("newVariousFolder1");
		String folder2 = generateRandomSuffix("newVariousFolder2");
		Folders oldFolders = app.getFolderHelper().getFolders();
		assertThat(app.getFolderHelper().createFolder(folder1), is(nullValue()));
		Folders newFolders1 = app.getFolderHelper().getFolders();
		assertThat(newFolders1, equalTo(oldFolders.withAdded(folder1)));
		assertThat(app.getFolderHelper().createFolder(folder2), is(nullValue()));
		Folders newFolders2 = app.getFolderHelper().getFolders();
		assertThat(newFolders2, equalTo(newFolders1.withAdded(folder2)));
	}

	@Test(enabled = true)
	public void testFoldersWithSameNameCreation()
	{
		String folder = generateRandomSuffix("newSameFolder");
		Folders oldFolders = app.getFolderHelper().getFolders();
		assertThat(app.getFolderHelper().createFolder(folder), is(nullValue()));
		Folders newFolders1 = app.getFolderHelper().getFolders();
		assertThat(newFolders1, equalTo(oldFolders.withAdded(folder)));
		assertThat(app.getFolderHelper().createFolder(folder), is("Duplicated folder name. A new folder hasn't been added."));
		Folders newFolders2 = app.getFolderHelper().getFolders();
		assertThat(newFolders2, equalTo(newFolders1));
	}

}
